<?php

if (! defined('SIMPLE_TEST')) {
    define('SIMPLE_TEST', '../simpletest/');
}
require_once(SIMPLE_TEST . 'autorun.php');

require_once '../Sql/DBVentanaDAO.php';
require_once '../Sql/conexion.php';
require_once '../Sql/claseDB.php';
require_once '../Exception/CustomException.php';
require_once '../Class/Ventana.php';


class DBVentanaDAOTest extends UnitTestCase {

    function DBVenatanaDAOTest() {
        $this->UnitTestCase();
    }

     public function testgetPrecio() {
        $DBVentanaDAOTest = new DBVentanaDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_ventana
                            VALUES (-1, 'Prueba Nombre', 
                            'Prueba Color', 'Prueba Otro Color', 
                            10, 11, 12, 13, 14, 1)" );

        $Precio = $DBVentanaDAOTest->getPrecio( -1, 1);
        $this->assertEqual( $Precio['ANCHO_COLOR'], 10 );
        $this->assertEqual( $Precio['ALTO_COLOR'], 11 );
        $this->assertEqual( $Precio['ACCESORIO'], 14 );
        $DBConn->consulta("DELETE FROM costo_ventana
                          WHERE CVT_ID = -1" );
     }

     public function testgetEspesor() {
        $DBVentanaDAOTest = new DBVentanaDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO puerta_ventana_cristal
                            VALUES (-1, NULL, NULL, 'VENTANA',
                            10, 1);" );

        $Espesor = $DBVentanaDAOTest->getEspesor( -1 );
        $this->assertEqual( $Espesor, 10 );
        $DBConn->consulta("DELETE FROM puerta_ventana_cristal
                          WHERE PVC_ID = -1" );
     }

     public function testgetNombre() {
        $DBVentanaDAOTest = new DBVentanaDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_ventana
                            VALUES (-1, 'Prueba Nombre',
                            'Prueba Color', 'Prueba Otro Color',
                            10, 11, 12, 13, 14, 1)" );

        $Nombre = $DBVentanaDAOTest->getNombre( -1 );
        $this->assertEqual( $Nombre, 'Prueba Nombre' );
        $DBConn->consulta("DELETE FROM costo_ventana
                          WHERE CVT_ID = -1" );
     }

     public function testgetInstalacion() {
        $DBVentanaDAOTest = new DBVentanaDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_suministro_instalacion
                            VALUES (-1, 'Prueba Nombre', 1, 1.0000,
                            1);" );

        $Precio = $DBVentanaDAOTest->getInstalacion( 'Prueba Nombre' );
        $this->assertEqual( $Precio, 1.0000 );
        $DBConn->consulta("DELETE FROM costo_suministro_instalacion
                          WHERE CSI_ID = -1" );
     }

      public function testsetVentana() {
        $DBVentanaDAOTest = new DBVentanaDAO();
        $miVentana = new Ventana('Prueba Nombre', 'Prueba Color', 
                                'Prueba Cristal', 'Prueba Cristal Color', 
                                10, 11, 12, 13, 14, 15, 16, 1, 17, 18);
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO presupuesto
                           VALUES (-1, 'PRESUPUESTO',
                           '2010-06-04', NULL, NULL,
                           NULL, 1, 1)" );


        $DBVentanaDAOTest->setVentana( $miVentana, -1 );
        $DBConn->consulta( "SELECT * FROM Ventana
                        WHERE VTA_NOMBRE = 'Prueba Nombre'
                        AND VTA_CRISTAL = 'Prueba Cristal'
                        AND VTA_COLOR = 'Prueba Color'
                        AND VTA_CRISTAL_COLOR = 'Prueba Cristal Color'
                        AND VTA_ESPESOR = 10
                        AND VTA_ANCHO = 11
                        AND VTA_ALTO = 12
                        AND VTA_PRECIO_ANCHO = 13
                        AND VTA_PRECIO_ALTO = 14
                        AND VTA_PRECIO_ACCESORIO = 15
                        AND VTA_PRECIO_CRISTAL = 16
                        AND VTA_PRECIO_ESMERILADO = 17
                        AND VTA_CANTIDAD = 1
                        AND VTA_STATUS = 1
                        ORDER BY VTA_ID DESC  " );

        $fila = $DBConn->extraer_registro();
        $id = $fila['VTA_ID'];
        $this->assertEqual( $fila['VTA_NOMBRE'], 'Prueba Nombre' );
        $this->assertEqual( $fila['VTA_CRISTAL'], 'Prueba Cristal' );
        $this->assertEqual( $fila['VTA_COLOR'], 'Prueba Color' );
        $this->assertEqual( $fila['VTA_CRISTAL_COLOR'], 'Prueba Cristal Color' );
        $this->assertEqual( $fila['VTA_ESPESOR'], 10 );
        $this->assertEqual( $fila['VTA_ANCHO'], 11 );
        $this->assertEqual( $fila['VTA_ALTO'], 12 );
        $this->assertEqual( $fila['VTA_PRECIO_ANCHO'], 13 );
        $this->assertEqual( $fila['VTA_PRECIO_ALTO'], 14 );
        $this->assertEqual( $fila['VTA_PRECIO_ACCESORIO'], 15 );
        $this->assertEqual( $fila['VTA_PRECIO_CRISTAL'], 16 );
        $this->assertEqual( $fila['VTA_PRECIO_ESMERILADO'], 17 );
        $this->assertEqual( $fila['VTA_CANTIDAD'], 1 );

        $DBConn->consulta( "SELECT *
                            FROM detalle_presupuesto
                            WHERE DPR_PTO_ID = -1" );

        $fila = $DBConn->extraer_registro();
        $this->assertEqual( $fila['DPR_PTO_ID'], -1 );
        $this->assertEqual( $fila['DPR_VTA_ID'], $id );
        $DBConn->consulta( "DELETE FROM detalle_presupuesto
                            WHERE DPR_VTA_ID = $id
                            AND DPR_PTO_ID = -1" );

        $DBConn->consulta( "DELETE FROM presupuesto
                            WHERE PTO_ID = -1" );

        $DBConn->consulta( "DELETE FROM puerta
                            WHERE VTA_ID = $id" );
      }


}
?>

